package me.muci.A_base.processingFlow;

import com.sun.deploy.util.StringUtils;
import org.junit.Test;

import java.io.*;

/**
 * ClassName: OtherStreamTest
 * <p>
 * Description:
 * 1. 标准的输入输出流
 * 2. 打印流
 * 3. 数据流
 * <p>
 * date: 2021/8/17 11:00
 *
 * @author muci
 * @since JDK 1.8
 */
public class OtherStreamTest {

    /**
     * 标准的输入 输出流
     * System.in  System.out
     * setIn() / setOut()方式重新指定输入和输出的流
     * <p>
     * 键盘输入字符串，控制台全大写输出，输入 e 或 exit 时退出
     */

    public static void main(String[] args) {
        try (
                InputStreamReader isr = new InputStreamReader(System.in);
                BufferedReader br = new BufferedReader(isr);
        ) {
            while (true) {
                String data = br.readLine();
                if ("e".equalsIgnoreCase(data) || "exit".equalsIgnoreCase(data)) {
                    System.out.println("程序结束");
                    break;
                }
                System.out.println("data.toUpperCase() = " + data.toUpperCase());
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 打印流
     * PrintStream PrintWriter
     */
    @Test
    public void test() {
        PrintStream ps = null;
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(new File("src\\main\\resources\\inputStreamReader\\file.txt"));
            ps = new PrintStream(fos , true);
            if (ps != null){
                System.setOut(ps);
            }
            for (int i = 0; i <= 255; i++) {
                System.out.println((char) i);
                if (i % 50 == 0){
                    System.out.println();
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }finally {
            ps.close();
        }
    }

    /**
     * 数据流
     * DataInputStream DataOutputStream
     * 为了方便操作Java中的基本数据类型和String类型
     */
}
